clear all
set more off, permanently

save  "...\PADDD_impact.dta"

***************************** prepare data ************************************

*** pixels reduced in size in 2012 
gen enacR_12_B3=1 if enacR_0912_B3==1 & year_PADDD==2012
replace enacR_12_B3=0 if enacR_0912_B3==0

*before their reduction
gen R12protected2000_B3=1 if Rprotected2000_B3==1 & year_PADDD==2012
replace R12protected2000_B3=0 if Rprotected2000_B3==0 

*** pixels reduced in size in 2010 
gen enacR_10_B3=1 if enacR_0912_B3==1 & year_PADDD==2010
replace enacR_10_B3=0 if enacR_0912_B3==0

*state 
merge m:m PADDD using  "C:\Users\dkeles\Documents\these\article2\important\desigPA.dta", gen(mergedesig)
gen desig=1 if Designation=="Federal"
replace desig=1 if Designation=="federal"
replace desig=2 if Designation=="State"
replace desig=2 if Designation=="state"
bysort ID1: fillmissing desig, with(any)
drop mergedesig

gen enacRS_10_B3=enacR_10_B3
replace enacRS_10_B3=. if (enacR_10_B3==1 & desig!=2)

*before their reduction
gen R10protected2000_B3=1 if Rprotected2000_B3==1 & year_PADDD==2010
replace R10protected2000_B3=0 if Rprotected2000_B3==0 

*** pixels reduced in size in 2009 
gen enacR_09_B3=1 if enacR_0912_B3==1 & year_PADDD==2009
replace enacR_09_B3=0 if enacR_0912_B3==0

*before their reduction
gen R09protected2000_B3=1 if Rprotected2000_B3==1 & year_PADDD==2009
replace R09protected2000_B3=0 if Rprotected2000_B3==0 

******************************* matching ***************************************

set seed 12345 
gen sortorder = runiform()
sort sortorder


*** 2009 roraima
xi: psmatch2 enacR_09  i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108 TMF_2001 TMF_2002 TMF_2003 TMF_2004 TMF_2005 TMF_2006 TMF_2007 TMF_2008  if  enacR_09!=. & ID_state==23, outcome(TMF_1015) caliper(0.5) ties ai(3) n(3)  common logit odds
foreach var in  _self_TMF_1015 _nn  _n1   _id _TMF_1015 _weight _support _treated _pscore {
gen roraima`var'=`var'
}
pstest  i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108 TMF_2001 TMF_2002 TMF_2003 TMF_2004 TMF_2005 TMF_2006 TMF_2007 TMF_2008 , t(enacR_09) mweight(roraima_weight) support (roraima_support) both 

*** 2012 para

xi: psmatch2 enacR_12  i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108 TMF_2001 TMF_2002 TMF_2003 TMF_2004 TMF_2005 TMF_2006 TMF_2007 TMF_2008 TMF_2009 TMF_2010 TMF_2011  if  enacR_12!=. & ID_state==14 ,  outcome(TMF_1315)  caliper(0.5) ties ai(1) n(1) norepl common logit odds
foreach var in  _self_TMF_1315 _nn  _n1   _id _TMF_1315 _weight _support _treated _pscore {
gen para`var'=`var'
}
pstest  i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108 TMF_2001 TMF_2002 TMF_2003 TMF_2004 TMF_2005 TMF_2006 TMF_2007 TMF_2008 TMF_2009 TMF_2010 TMF_2011, t(enacR_12) mweight(para_weight) support (para_support) both 

////// 2010 rondonia

xi: psmatch2 enacRS_10 i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108 TMF_2001 TMF_2002 TMF_2003 TMF_2004 TMF_2005 TMF_2006 TMF_2007 TMF_2008 TMF_2009   if enacR_10!=. & ID_state==22 ,   outcome(TMF_1115) caliper(0.5) ties ai(1) n(1) norepl common logit odds
foreach var in  _self_TMF_1115 _nn  _n1   _id _TMF_1115 _weight _support _treated _pscore {
gen rondonia`var'=`var'
}
pstest i.qual dist_cities  dist_roads2008 dist_rivers slope elevation _prec0108 TMF_2001 TMF_2002 TMF_2003 TMF_2004 TMF_2005 TMF_2006 TMF_2007 TMF_2008 TMF_2009  , t(enacRS_10) mweight(rondonia_weight) support (rondonia_support) both 
drop  _nn _n1  _id  _weight _support _treated _pscore
mhbounds TMF_1115, gamma(1 (0.10) 10) treated(rondonia_treated) weight(rondonia_weight) support(rondonia_support) 


save "...\results_impact_TMF.dta", replace

